home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ma93 / GadTools / GadTools.txt < prev    next >
Encoding:
Text File  |  1993-05-19  |  17.3 KB  |  397 lines

  1. (c) Copyright 1993 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7.  
  8. Features of V39 GadTools
  9.  
  10. by Mark Ricci
  11.  
  12.  
  13. The V39 GadTools library has been upgraded with new features and
  14. capabilities that support the enhanced graphic capabilities of the AA
  15. chipset.  Other improvements include support for IDCMP_GADGETHELP
  16. events, more support for IDCMP_GADGETUP events, scalable imagery and a
  17. new function, GT_GetGadgetAttrs(), to obtain the values of certain
  18. gadget attributes.
  19.  
  20. This article assumes you are familiar with the previous version of the
  21. GadTools library.  If not, you should refer to the ``GadTools Library''
  22. chapter of the Amiga ROM Kernel Reference Manual: Libraries for an
  23. in-depth explanation of GadTools.  You should also refer to the
  24. GadTools Autodoc for complete explanations of the GadTools functions.
  25. All tags and constants referenced in this article are defined in
  26. <libraries/gadtools.h> and <intuition/intuition.h>.
  27.  
  28.  
  29. The NewLook Menus
  30.  
  31. For V37, Intuition received a facelift.  V37 introduced the ``NewLook''
  32. rendering scheme, which improved the appearance of most of the elements
  33. of the Amiga user interface (windows, system gadgets, standard Boopsi
  34. classes, etc.).  One element of the Amiga's GUI that escaped the
  35. NewLook was the menu system.
  36.  
  37. For V39, Intuition added the NewLook to its menus.  When Intuition
  38. renders NewLook menus, it gets the colors for the menu from the Palette
  39. Preferences set by the user.  Before V39, Intuition used the window's
  40. DetailPen and BlockPen to draw the menu and the colors of the MenuItems
  41. depended on the MenuItem's IntuiText or Image structure.
  42.  
  43. GadTools fully supports Intuition's NewLook menus.  To make GadTools
  44. use the NewLook color scheme for a window's menus, an application needs
  45. to do two things.  First, it needs to tell Intuition that it wants
  46. NewLook menu imagery for the window.  It does this when opening the
  47. window by passing the {WA_NewLookMenus, TRUE} tag/value pair to
  48. OpenWindowTags().  Second, the application needs to remind GadTools
  49. that the window uses NewLook imagery for its menus.  The application
  50. does this by passing the {GTMN_NewLookMenus, TRUE} tag/value pair to
  51. LayoutMenus():
  52.  
  53.     struct VisualInfo *vi;
  54.  
  55.     LayoutMenus(menusready, vi, GTMN_NewLookMenus, TRUE, TAG_END);
  56.  
  57. Instead of using the GTMN_NewLookMenus tag, it's possible to set the
  58. menu colors yourself by using the GTMN_FrontPen tag to set the pen
  59. number for rendering menu text.  In addition to this tag, you must set
  60. the screen's BARDETAILPEN and BARTRIMPEN to match the menu text pen and
  61. set the BARBLOCKPEN to the color you want for the title bar.  However,
  62. you cannot control how Intuition complements menu items and you do not
  63. automatically get the user's menu color preferences, so you will not
  64. get as perfect NewLook menu as you would by leaving it to the system.
  65.  
  66.  
  67. Gadgets
  68.  
  69. Most GadTools gadgets received new attributes in V39.  These include
  70. new IDCMP events, the ability to specify rendering pens, and scalable
  71. imagery.
  72.  
  73. IDCMP Events
  74.  
  75. Button, integer and string gadgets can send IDCMP_GADGETDOWN events by
  76. setting the GA_Immediate tag to TRUE.
  77.  
  78. Disabling
  79.  
  80. MX and listview gadgets join the other GadTools gadgets in having a
  81. disable attribute.  Set the GA_Disabled tag to TRUE to disable, and
  82. FALSE to re-enable.
  83.  
  84. Scalable Imagery
  85.  
  86. Checkbox and MX gadgets are no longer fixed in size.  You can scale
  87. them to any width and height.  If you do not specify scaling, GadTools
  88. uses its built-in default dimensions.  These dimensions,  which are
  89. defined in <libraries/gadtools.h> , are CHECKBOXWIDTH and
  90. CHECKBOXHEIGHT for checkbox gadgets, and  MXWIDTH by MXHEIGHT for MX
  91. gadgets.
  92.  
  93. To scale a checkbox gadget, set the GTCB_Scaled tag to TRUE, and set
  94. the desired width and height in the ng_Width and ng_Height fields of
  95. the NewGadget structure.  The default value of GTCB_Scaled is FALSE,
  96. meaning use the default size of 26 by 11, the values of CHECKBOXWIDTH
  97. and CHECKBOXHEIGHT, respectively.
  98.  
  99. To scale an MX gadget, set the GTMX_Scaled tag to TRUE, and set the
  100. desired width and height in the ng_Width and ng_Height fields of the
  101. NewGadget structure.  The default value of GTMX_Scaled is FALSE,
  102. meaning use the default size of 17 by 9, the values of MXWIDTH by
  103. MXHEIGHT, respectively.  If you scale MX gadgets, you must also set the
  104. GTMX_Spacing tag to NewGadget.ng_TextAttr->ta_YSize + 1 to properly
  105. space the buttons with respect to the font.
  106.  
  107.  
  108. Rendering Pens, Display Format, Justification, Clipping and Display Size
  109.  
  110. Application writers use number, text, and to some degree, slider
  111. gadgets, to present information to the user.  The new attributes for
  112. these gadgets improve the presentation of the information.
  113.  
  114. You can specify any pen for rendering the foreground and the background
  115. of number and text gadgets.  This allows you to use color for emphasis
  116. or aesthetics.  For example, you might use red as the foreground color
  117. in a text gadget for emphasis.  You can also use C-language-like
  118. formatting strings for the displays, e.g., %lx  would give you
  119. hexadecimal output in a number gadget.  The Exec RawDoFmt() function
  120. processes this string, so refer to that function for details.
  121.  
  122. Text clipping is another new attribute.  It clips the display to fit
  123. within the borders of the gadget.  This prevents the text or number
  124. from running over the border of a gadget if it's too large for the
  125. gadget.  Along with text clipping, the number, text and slider gadgets
  126. can left, center and right justify their displays.
  127.  
  128. Finally, you can specify the size of the string buffer that number and
  129. slider gadgets use when formatting their text.  This buffer must be
  130. large enough to hold the entire string generated by the gadget, as the
  131. gadget doesn't do any bounds checking on the buffer.  Underestimating
  132. the size of the buffer will cause the gadget to overwrite the buffer,
  133. overwriting whatever happens to follow the buffer in memory.
  134.  
  135. For number gadgets, the GTNM_FrontPen tag specifies the pen to use for
  136. rendering the number.  The default is DrawInfo->dri_Pens[TEXTPEN]).
  137. GTNM_BackPen specifies the pen to use for rendering the background of
  138. the number.  The default is to use the background color of the gadget's
  139. window.
  140.  
  141. GTNM_Justification specifies the type of justification within the
  142. gadget box.  GTJ_LEFT renders the number flush with the left side of
  143. the gadget, GTJ_RIGHT renders the number flush with the right side, and
  144. GTJ_CENTER centers the number.  The default is GTJ_LEFT.
  145.  
  146. GTNM_Format specifies the C-language-like formatting string used to
  147. display the number.  You must use the ``l'' (long) modifier.  The
  148. default is ``%ld''.  The gadget passes the formatting string to the
  149. exec.library function RawDoFmt(), which generates the string that
  150. appears in the number gadget.  See the Autodoc for RawDoFmt() for more
  151. information on the formatting string.
  152.  
  153. If an application changes the default formatting string with the
  154. GTNM_Format tag, the string that the number gadget displays may become
  155. significantly longer.  For example, if the application uses the format
  156. string ``my number is %ld'', when the gadget processes the formatting
  157. string with RawDoFmt(), RawDoFmt() generates a string at least 14
  158. characters long.  By default, the gadget sets aside a 10 byte buffer
  159. for RawDoFmt() to use, so the formatting string above is too long for
  160. the default buffer.  The tag GTNM_MaxNumberLen sets the size of this
  161. buffer.
  162.  
  163. GTNM_Clipped controls text clipping.  The default behavior differs
  164. between number gadgets with borders and number gadgets without borders.
  165. For bordered number gadgets, the default is TRUE--clip the display to
  166. fit within the gadget borders.  For gadgets without borders, the
  167. default is FALSE--no clipping.
  168.  
  169. Text gadgets also have a new set of attributes that correspond to the
  170. new number gadget attributes.  These corresponding tags are:
  171. GTTX_FrontPen, GTTX_BackPen, GTTX_Justification, and GTTX_Clipped.
  172. There is no corresponding text gadget tag for GTMN_MaxNumberLen or
  173. GTMN_Format.
  174.  
  175. Slider gadgets use the GTSL_Justification tag with the constants listed
  176. above (GTJ_LEFT, GTJ_RIGHT, and GTJ_CENTER) to control justification of
  177. the gadgets numeric display.  The GTSL_MaxPixelLen tag specifies the
  178. maximum pixel size of the level display for any value of the slider.
  179. This is primarily useful when dealing with proportional fonts.  The
  180. default is the font's character width (from the font's
  181. TextFont->tf_XSize field) multiplied by the value in the
  182. GTSL_MaxLevelLen tag.
  183.  
  184.  
  185. New Gadget-Specific Attributes
  186.  
  187. MX gadgets can now have titles.  The gadget obtains its title from the
  188. ng_GadgetText field of the NewGadget structure.  The GTMX_TitlePlace
  189. tag specifies where to place the title.  The possible values are:
  190.  
  191.     PLACETEXT_LEFT  Right-align text on left side
  192.     PLACETEXT_RIGHT Left-align text on right side
  193.     PLACETEXT_ABOVE Center text above
  194.     PLACETEXT_BELOW Center text below
  195.  
  196. For compatibility reasons, GadTools will not put a title on the MX
  197. gadget if the GTMX_TitlePlace tag is not present.
  198.  
  199.  
  200. Listviews
  201.  
  202. Listview gadget improvements include forced display of an item,
  203. highlighting of the selected item in the listview and custom callback
  204. hooks.
  205.  
  206. The GTLV_MakeVisible tag specifies the number of the item that should
  207. be forced into the viewing area.  It overrides the GTLV_Top tag.
  208.  
  209. In V37, a listview identified its currently selected item by displaying
  210. it in a text gadget beneath the listview.   The tag GTLV_ShowSelected
  211. specifies how the listview indicates which item is the currently
  212. selected item.  If set to NULL, the listview places a highlight bar
  213. over the currently selected item.  If GTLV_ShowSelected points to a
  214. string gadget, the listview displays the selected item in the string
  215. gadget in addition to a highlight bar.
  216.  
  217. You can use callback hooks to render a listview's items.  The listview
  218. in the V39 Palette Preferences editor uses a callback hook to display
  219. the standard user interface pens.  The callback hook makes it possible
  220. for each item to display the pen color in addition to the pen name.
  221. The pen color appears in a little box at the left edge of each item in
  222. the listview.
  223.  
  224.  
  225. Palette
  226.  
  227. GTPA_NumColors sets the number of colors to display in the palette
  228. gadget.  This overrides the GTPA_Depth tag and allows numbers that are
  229. not powers of 2 (which was a limitation of the V37 palette gadget).
  230. The default is 2.
  231.  
  232. Palette gadgets can now have their own array of pen numbers.
  233. GTPA_ColorTable is a pointer to a array of pen numbers.  The array must
  234. contain at least as many entries as there are colors displayed in the
  235. palette gadget.  The default is NULL which causes a 1-to-1 mapping of
  236. pen numbers.  That means if you don't specify this tag, your palette
  237. will use pen number 0 through pen n-1, where n is the number of colors
  238. you set in GTPA_NumColors.  For example, if you set GTPA_NumColors to 6
  239. and don't specify GTPA_ColorTable, you will get a pen array of pens 0,
  240. 1, 2, 3, 4, and 5.
  241.  
  242. A pen array you specify looks like this:
  243.  
  244.     UBYTE colors[8]= {1,2,15,6,0,3,8};
  245.  
  246. Setting GTPA_ColorTable to this array indicates that the palette pens
  247. are 1, 2, 15, 6, 0, 3 and 8, respectively.  Note that you have to
  248. allocate pens to be certain you can use them and control them.  See the
  249. Amiga OS V39 Developer Release Notes for information on allocating and
  250. sharing pens.
  251.  
  252. You cannot use the GTPA_ColorTable tag with the GTPA_ColorOffset tag.
  253. The GTPA_ColorOffset tag specifies which pen to use as the first pen of
  254. a palette.  For example, if you set it to 4, the first pen used in the
  255. palette will be pen 4.  If you use the GTPA_ColorTable tag, the
  256. GTPA_ColorOffset tag is ignored.
  257.  
  258. However, you can do color offsets with a color table by setting the
  259. value of the GTPA_ColorTable tag to point to the color table plus the
  260. offset you want.  In the table above, you could specify pen 6 (the
  261. fourth member of the table) as the first pen to use by setting
  262. GPTA_ColorTable in this manner:
  263.  
  264.     CreateGadget(PALETTE_KIND, gad, &ng,
  265.                  GTPA_ColorTable, &colors[3],
  266.                  TAG_END);
  267.  
  268. Note that the GTPA_NumColors tag is not present in the call above.
  269. This will default the number of colors to two, so the palette gadget
  270. created above will be a two color gadget that uses pens 6 and 0, the
  271. fourth and fifth pens in the array.
  272.  
  273.  
  274. Obtaining Gadget Attributes
  275.  
  276. Prior to V39, the only way to obtain the attributes of a GadTools
  277. gadget was through the Code field of an IDCMP_GADGETUP IntuiMessage.
  278. In addition to having to wait until the user clicked on a gadget, this
  279. method limited you to obtaining one attribute at a time.
  280.  
  281. A new GadTools function, GT_GetGadgetAttrs() obtains a gadget's
  282. attributes.  You may call the function at any time after creating a
  283. gadget and for as many attributes as the function supports for that
  284. gadget.
  285.  
  286. GT_GetGadgetAttrs() accepts a taglist of the attributes to obtain.  An
  287. application passes it the address of the gadget, the address of the
  288. window containing the gadget, a NULL field (this field is reserved for
  289. later use and must be NULL for now), and a taglist.  Each attribute
  290. value pair in the taglist supplies the ID of the tag to get (in ti_Tag)
  291. and an address where GT_GetGadgetAttrs() can store the tag's value.
  292. Since all tag values are longwords, expect GT_GetGadgetAttrs() to copy
  293. a longword for each attribute you request.  The function returns the
  294. number of attributes it obtained.
  295.  
  296. LONG how_many, top_item = 0, selected_item = 0;
  297.  
  298. how_many = GT_GetGadgetAttrs( listview_gad, win, NULL,
  299.                               GTLV_Top, &top_item,
  300.                               GTLV_Selected, &selected_item,
  301.                               TAG_DONE );
  302.  
  303. How_many contains the number of gadget attributes GT_GetGadgetAttrs()
  304. obtained.  GT_GetGadgetAttrs() copies the value of the listview top and
  305. the selected item into top_item and selected_item, respectively.  Use
  306. longword targets to hold the returned values.
  307.  
  308. GT_GetGadgetAttrs() supports GA_Disabled (TRUE if the gadget is
  309. disabled; FALSE if the gadget is active) for all GadTools gadgets
  310. except text and number gadgets.  Other attributes are specific to each
  311. gadget as follows:
  312.  
  313.     Checkbox - GTCB_Checked returns TRUE if the checkbox gadget
  314.     is checked, or FALSE if the gadget is not checked.
  315.  
  316.     Cycle - GTCY_Active returns the ordinal number, counting up
  317.     from zero, of the active choice.  GTCY_Labels returns a
  318.     pointer to the NULL-terminated array of choices.
  319.  
  320.     Integer - GTIN_Number returns the contents of the gadget.
  321.  
  322.     Listview - GTLV_Top returns the ordinal number, counting up
  323.     from zero, of the top item.  GTLV_Selected returns the
  324.     ordinal number of the selected item.  GTLV_Labels returns a
  325.     pointer to the List structure associated with the gadget.
  326.  
  327.     MX - GTMX_Active returns the ordinal number, counting up
  328.     from zero, of the active selection.
  329.  
  330.     Palette - GTPA_Color returns the ordinal number of the
  331.     selected color. This number corresponds to the selected
  332.     color's position in the palette's GTPA_ColorTable array.
  333.     GTPA_ColorOffset returns the ordinal number of the first
  334.     color used in the palette.  GTPA_ColorTable returns a
  335.     pointer to the table of pen numbers used for the gadget, if
  336.     there is one.
  337.  
  338.     Scroller - GTSC_Top returns the number of the top line
  339.     visible in the scroller.  GTSC_Total returns the total
  340.     number of lines in the scroller.  GTSC_Visible returns the
  341.     number of visible lines in the scroller.
  342.  
  343.     Slider - GTSL_Min returns the minimum value of the slider.
  344.     GTSL_Max returns the maximum value of the slider.
  345.     GTSL_Level returns the current level of the slider.
  346.  
  347.     String - GTST_String returns a pointer to the gadget's
  348.     buffer.
  349.  
  350.     Text - GTTX_Text returns a pointer to the gadget's buffer.
  351.  
  352.  
  353. Message Handling - ExtIntuiMessage Structure
  354.  
  355. For V39, the IntuiMessage structure has been extended to allow for
  356. tablet support.  The GadTools message handling
  357. functions--GT_FilterIMsg(), GT_GetIMsg(), GT_PostFilterIMsg() and
  358. GT_ReplyIMsg()--work with the extended IntuiMessage structure,
  359. ExtIntuiMessage, but are backwards compatible with IntuiMessage.
  360.  
  361.  
  362. Gadget Help
  363.  
  364. All GadTools gadgets support Intuition's gadget help feature.  You
  365. enable this by calling the intuition.library function HelpControl().
  366. Gadget help is either on or off for all GadTools gadgets in a window;
  367. you cannot selectively enable it for certain gadgets as you can with
  368. Intuition gadgets.  For more information, refer to page IV-114 of the
  369. ``Boopsi in Release 3'' article in the January/February 1993 issue of
  370. Amiga Mail.
  371.  
  372.  
  373. Bevel Box
  374.  
  375. Bevel boxes now come in three types that you specify with
  376. GTBB_FrameType.  BBFT_BUTTON generates the type of box used around
  377. button gadgets.  BBFT_RIDGE generates the type of box used for string
  378. gadgets.  BBFT_ICONDROPBOX generates a box suitable for a standard icon
  379. drop box imagery.  The default is BBFT_BUTTON.  These frame types are
  380. similar to the Boopsi imageclass frame types FRAME_BUTTON, FRAME_RIDGE,
  381. and FRAME_ICONDROPBOX, that are pictured on page IV-120 of the ``Boopsi
  382. in Release 3'' article in the January/February 1993 issue of Amiga Mail.
  383.  
  384.  
  385. Example Code - NewGadgets.c
  386.  
  387. The example code below is a demonstration of some of the V39 GadTools
  388. changes and how to specify them in your code.  You'll notice that it
  389. lacks many of the features required to actually use the gadgets.  This
  390. is by design.  The intent is for you to modify an existing application
  391. using the example as a guide.
  392.  
  393. NewGadgets.c produced the screen shot below.
  394.  
  395.  
  396. [Figure 1]
  397.